<?php

namespace App\Exports\Game\Data\Settlement;

use App\Exports\Export;

class InfoExport extends Export
{

    /**
     * 映射标题行
     *
     * @return array
     */
    protected function headings(): array
    {
        return trans('view.game.data.settlement.headings');
    }

    /**
     * 映射数据行
     *
     * @param \Illuminate\Database\Eloquent\Model $item
     * @return array
     */
    protected function map($item): array
    {
        return [
            $item->sn,
            $item->uid,
            $item->org->name ?? $item->plat_code,
            $item->account_id,
            $this->games[$item->game_id] ?? $item->game_id,
            $item->currency,
            $item->bet_base,
            $item->bet_num,
            $item->gain_player,
            $item->gain_sys,
            $item->balance_start,
            $item->balance_end,
            $this->playerTypeList[$item->player_type] ?? $item->player_type,
            $this->statusList[$item->status] ?? $item->status,
            timestamp_to_datetime($item->start_time),
            timestamp_to_datetime($item->end_time),
            $item->usd['rate'] ?? null,
            $item->usd['bet_base'],
            $item->usd['bet_num'],
            $item->usd['gain_player'],
            $item->usd['gain_sys'],
            $item->usd['balance_start'],
            $item->usd['balance_end'],
        ];
    }

    /**
     * 玩家类型
     *
     * @var array
     */
    protected $playerTypeList;

    /**
     * 状态
     *
     * @var array
     */
    protected $statusList;

    /**
     * 游戏
     *
     * @var array
     */
    protected $games;

    /**
     * 初始化操作
     */
    protected function init()
    {
        // 文件名称
        $this->filename = trans('view.game.data.settlement.filename');

        // 玩家类型
        $this->playerTypeList = trans('view.game.data.settlement.playerTypeList');

        // 状态
        $this->statusList = trans('view.game.data.settlement.statusList');

        // 游戏
        $this->games = trans('view.game.games');
    }
}
